package bairui.international.console.web.controller.order.product;

import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.querydsl.core.BooleanBuilder;

import bairui.international.model.domain.jpa.QTB_ProductOrder;
import bairui.international.model.domain.jpa.TB_ProductOrder;
import bairui.international.service.Service_ProductOrder;

/**
 *
 * 导出
 *
 * @generated
 * 
 * @see STest_C_ProductOrder_Export_ExcelExport 测试
 *
 */
@Controller
public class C_ProductOrder_Export_ExcelExport
 extends SC_ProductOrder_Export_ExcelExport 
{
	
	private final QTB_ProductOrder QProductOrder = QTB_ProductOrder.tB_ProductOrder;
	@Autowired private Service_ProductOrder service_ProductOrder;
	
	/**
	 * 导出Excel文件
	 */
	@SuppressWarnings("serial")
	@Action(ExcelExport.class)
	@PostMapping(ExcelExport.RequestMappingValue)
	public void excelExport(
		HttpServletRequest request,
		HttpServletResponse response,
		@Valid ExcelExport.Input input
	) throws Exception {
		BooleanBuilder query = C_ProductOrder_Page_Page.filter(QProductOrder, request);
		List<Long> ids = input.getId();
		if(!ids.isEmpty()){
			query.and(QProductOrder.id.in(ids));
		}
		//
		java.util.List<TB_ProductOrder> list = service_ProductOrder.list(
						it->query, 
						it->C_ProductOrder_Page_Page.sort(it,request)
					).getContent();
		//
		ExcelExport.Output.output(
				list
					.stream()
					.map(it->new ExcelExport.Output.Model(it){
							@Override protected void assign_before() {
							}
							@Override public String assignUserName() {
								if(null == it.getUserInfo()){
									return null;
								}
								return it.getUserInfo().getRealName();
							}
						}
					)
					.collect(Collectors.toList()),
				request, 
				response
			);
	}
	

}
